<template>
    <div class="tmpl">
        <div class="title">
            <h2>{{newsInfo.title}}</h2>
            <p>{{newsInfo.add_time | dateFmt('YYYY-MM-DD')}}
                &nbsp;{{newsInfo.click}}浏览&nbsp;分类:民生经济</p>
        </div>
        <div class="content">
            <p v-html="newsInfo.content"></p>
        </div>
        <!-- 评论子组件 -->
        <subcomment :commentId="this.$route.params.newsId">
        </subcomment>
    </div>
</template>

<style scoped>
    .title{
        padding: 5px;
        border-bottom: 1px solid rgba(92,92,92,0.2);
    }

    .content{
        padding: 5px;
    }

    h2{
        color: #0094ff;
        font-size: 16px;
        font-weight: 700;
    }
</style>

<script>
    import common from '../../tools/common.js';

    //导入评论子组件
    import subcomment from '../subcomponent/subcomment.vue';

    export default{
        data(){
            return {
                newsInfo : {}
            };
        },
        created(){
            this.getNewsInfoData();
            //console.log("newsinfo 创建啦");
        },
        destroyed(){
            //console.log("newsinfo 销毁啦");
        },
        methods:{
            getNewsInfoData(){
                //url
                const url = common.apihost+"api/getnew/"+this.$route.params.newsId;

                //send request
                this.$http.get(url).then(res=>{
                    this.newsInfo = res.body.message[0];
                },err=>{

                })
            }
        },
        components:{
            //subcomment:subcomment 这是全写
            subcomment //简写,确保属性名和值名称一样
        }
    }
</script>